package eu.codlab.twitteirb;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class PeersAdapter extends BaseAdapter{
	private TwittEirbActivity _parent;

	public PeersAdapter(TwittEirbActivity parent){
		_parent = parent;
	}
	@Override
	public int getCount() {
		return TwittEirbService.getService().getPeers().size();
	}

	@Override
	public Object getItem(int arg0) {
		return arg0<getCount() ? TwittEirbService.getService().getPeers().get(arg0) : null;
	}

	@Override
	public long getItemId(int arg0) {
		return arg0;
	}

	@Override
	public View getView(final int arg0, View arg1, ViewGroup parent) {
		//Log.d("refresh list","getVIew");
		View v = arg1;
		if (v == null) {

			LayoutInflater vi = (LayoutInflater)_parent.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			v = vi.inflate(R.layout.peer_item, null);
		}

		v.setOnClickListener(new OnClickListener(){

			@Override
			public void onClick(View v) {
				_parent.onClickLogin((String)getItem(arg0));
			}
			
		});
		String item = (String)getItem(arg0);

		TextView title = (TextView)v.findViewById(R.peer.nom);
		title.setText(""+item);
		return v;
	}

}
